﻿#region 命名空间

using System;
using System.Configuration;
using System.Diagnostics;
using System.Web.Security;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.WebUI.Admin
{
    /// <summary>
    ///     Admin_Login 的摘要说明。
    /// </summary>
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var config = CMSConfig.Instance();
            if (!config.Already)
            {
                Response.Redirect(@"../Install/Index.aspx");
            }

            if (!IsPostBack)
            {
                //读取上次登录时的账号
                if (Request.Cookies["Logined_UserName"] != null)
                {
                    this.txtUserName.Text = Request.Cookies["Logined_UserName"].Value;
                }

                //this.trValidateCode.Visible = config.PassCode;


                var th = new System.Threading.Thread(StatisticalUsers);
                th.Start(Request.Url);
            }
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var model = new User
            {
                UserName = this.txtUserName.Text,
                PassWord = this.txtPassword.Text
            };

            var resu = new LoginManage().TryLoginSystem(model, this.txtValidateCode.Text, false);

            if (string.IsNullOrEmpty(resu.Errors) == false)
            {
                MsgBox.Message(resu.Errors, this);
            }
            else
            {
                Response.Write("<script language='javascript'> parent.location.href='Index.aspx';</script>");
            }
        }

        private void StatisticalUsers(object url)
        {
            try
            {
                Uri u = null;
                if (url is Uri)
                {
                    u = url as Uri;
                }
                if (u.Host.ToLower().Contains("localhost") || u.Host.Contains("192.168.") ||
                    u.Host.Contains("WinnerCMS.com"))
                {
                }
            }
            catch
            {
            }
        }
    }
}